Ext.define('vacake.controller.AreaSelect', {
    extend: 'Ext.app.Controller',

    config: {
        routes: {
            'loadSelectArea': 'loadSelectArea'
        },
        refs: {
            mainView: 'mainView',
            homeView: 'homeView',
            areaSelectView: 'areaSelectView',
            backHomeButton: 'areaSelectView #back_home',
            titleBar: 'button[action=titleBar]'
        },
        control: {
            backHomeButton: {
                tap: 'backHomeButton_onTap'
            },
            areaSelectView: {
                select: 'areaList_onSelect'
            }
        }
    },
    loadSelectArea: function () {
        var areaSelectView = this.getAreaSelectView();
        if (areaSelectView == null) {
            areaSelectView = Ext.create("vacake.view.AreaSelect");
        }
        Ext.Viewport.animateActiveItem(areaSelectView, {type: 'slide', direction: 'left'});

    },
    backHomeButton_onTap: function () {
        Ext.Viewport.remove(this.getAreaSelectView(),true);
    },
    areaList_onSelect: function (list, record) {
        Ext.Viewport.mask({ xtype: 'loadmask', message: '加载数据中...'});
        if (window.localStorage.getItem('app_district_id') != record.get('cadid')) {
            //将选择的list的值存放到本地中
            window.localStorage.setItem('app_district_id', record.get('cadid'));//设置
            window.localStorage.setItem('app_district_name', record.get('name')); 
            Ext.Viewport.remove(this.getMainView(),true);
        }

        var mainView = this.getMainView();
        if (mainView == null) {
             mainView = Ext.create("vacake.view.Main");
        }
       Ext.Viewport.remove(this.getAreaSelectView(),true);
        Ext.Viewport.animateActiveItem(mainView, {type: 'slide', direction: 'right'});

    }
});